package cn.kgc.tangcco.quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @author 李昊哲
 * @Description
 * @create 2021/1/8 10:49
 */
public class QuartzTest {
    public static void main(String[] args) throws SchedulerException {
        // 1、创建Job对象 要做的事
        JobDetail job01 = JobBuilder.newJob(JobDemo01.class).build();
        JobDetail job02 = JobBuilder.newJob(JobDemo02.class).build();

        // 2、创建Trigger对象 在什么情况下或什么时间做

        SimpleScheduleBuilder simpleSchedule= SimpleScheduleBuilder.repeatSecondlyForever(5);
        SimpleTrigger simpleTrigger = TriggerBuilder.newTrigger().withSchedule(simpleSchedule).build();

        CronScheduleBuilder cronSchedule = CronScheduleBuilder.cronSchedule("0/5 * * * * ?");
        CronTrigger cronTrigger = TriggerBuilder.newTrigger().withSchedule(cronSchedule).build();

        // 3、创建Scheduler对象 调度Trigger对象和Job对象在什么情况下或什么时间做什么事
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.scheduleJob(job01,simpleTrigger);
        scheduler.scheduleJob(job02,cronTrigger);
        scheduler.start();
    }
}
